//
// Vue.use(Vuex);
//
// const store = new Vuex.Store({
//   state: {
//     token: localStorage.getItem("token") ? localStorage.getItem("token") : "",
//     userInfo: localStorage.getItem("userInfoForTdf") ? localStorage.getItem("userInfoForTdf") : {}
//   },
//   mutations: {
//     setToken(state, token) {
//       state.token = token;
//       localStorage.setItem("token", token);
//     },
//     delToken(state) {
//       state.token = "";
//       localStorage.removeItem("token");
//     },
//     setUserInfo(state, obj) {
//       state.userInfo = obj;
//       localStorage.setItem("userInfoForTdf", obj);
//     }
//   },
//   actions: {
//     // 前端 登出
//     FedLogOut({ commit }) {
//       return new Promise(resolve => {
//         commit('delToken', null)
//         commit('setUserInfo', null)
//         resolve()
//       })
//     }
//   },
//   modules: {}
// });
//
// export default store;



import Vue from 'vue'
import Vuex from 'vuex'
import app from './modules/app'
import permission from './modules/permission'
import tagsView from './modules/tagsView'
import user from './modules/user'
import dictionaries from './modules/dictionaries'
import getters from './getters'
import createPersistedState from 'vuex-persistedstate'

Vue.use(Vuex)

const store = new Vuex.Store({
  state: {
    themecolor: '#3C9AFB'// 默认为3C9AFB
  },
  mutations: {
    // 更新主题颜色
    setThemeColor(state, curcolor) {
      this.state.themecolor = curcolor
    }
  },
  modules: {
    app,
    permission,
    tagsView,
    user,
    dictionaries
  },
  getters,
  plugins: [createPersistedState({
    storage: window.localStorage,
    reducer(val) {
      return {
        // 只储存state中的
        themecolor: val.themecolor,
        user: val.user,
      }
    }
  })]
})

export default store

